#pragma once
#include "app.h"
#include "world.h"
#include "SDL.h"

class GameOfLife : public App
{
private:
	SDL_Rect hor_line = { 0, 0, 800, 2 };
	SDL_Rect ver_line = { 0, 0, 2, 500 };
	SDL_Rect test_box = { 4, 4, 14, 14 };
	World world;
	int around[8][2] = { {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1},{-1, 0}, {-1, -1} };
	int count = 20;
	void tick() override;
	void init() override;
	void random();
	int getCellAround(int x, int y) {
		int x_, y_;
		int count = 0;
		for (int i = 0; i < 8; ++i)
		{
			x_ = x + around[i][0];
			y_ = y + around[i][1];
			if (0 <= x_ && x_ < world.width && 0 <= y_ && y_ < world.height)
			{
				if (world.blocks[world.currBlocks][y_][x_])
				{
					++count;
				}
			}
		}
		return count;
	}
	bool start = false;
	void simulation();
	void onClick(SDL_Event* e);
	void onKeyEvent(SDL_Event* e);
public:
	GameOfLife();

};